home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
STUTTGART
/
LANG
/
GOFER
/
gs
/
iomonad
< prev
Wrap
Text File
|
1994-06-06
|
2KB
|
52 lines
------------------------------------------------------------------------------
-- This file contains a Gofer implementation of Lazy state threads, as
-- described in the PLDI '94 paper by John Launchbury and Simon Peyton
-- Jones, using new Gofer primitives added in Gofer 2.30.
--
-- This file is included for the benefit of those interested in
-- experimenting with the use of lazy functional state threads.
-- You may expect to see changes to the definitions in this file,
-- to track future proposals for monadic I/O in Haskell.
--
-- This file requires the standard, or cc prelude.
-- You will not be able to use this file unless the version of Gofer that
-- is installed on your machine has been compiled with the IO_MONAD flag
-- set to 1.
--
-- Mark P Jones, 1994
------------------------------------------------------------------------------
module LazyStateThd( thenST, thenST_, returnST, newVar, readVar, WriteVar,
mutVarEq, getch, putchar, thenIO, seqST, putString,
getchar
) where
infixr `thenST_`, `thenST`
primitive returnST "primSTReturn" :: a -> ST s a
primitive thenST "primSTBind" :: ST s a -> (a -> ST s b) -> ST s b
primitive newVar "primSTNew" :: a -> ST s (MutVar s a)
primitive readVar "primSTDeref" :: MutVar s a -> ST s a
primitive writeVar "primSTAssign" :: MutVar s a -> a -> ST s ()
primitive mutvarEq "primSTMutVarEq" :: MutVar s a -> MutVar s a -> Bool
primitive getch "primIOGetch" :: IO Char
primitive putchar "primIOPutchar" :: Char -> IO ()
primitive thenIO "primIOBind" :: ST s a -> (a -> ST s b) -> ST s b
instance Eq (MutVar s a) where (==) = mutvarEq
thenST_ :: ST s () -> ST s b -> ST s b
p `thenST_` q = p `thenST` \() -> q
seqST :: [ST s ()] -> ST s ()
seqST = foldr thenST_ (returnST ())
putString :: String -> IO ()
putString = seqST . map putchar
getchar = getch `thenST` \c ->
putchar c `thenST_`
returnST c
------------------------------------------------------------------------------